package com.alliance.shuwei.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alliance.shuwei.service.QiniuService;

@Controller
@RequestMapping("/admin/resources")
public class ResourceController {
	@Autowired
	private QiniuService qiniuService;

	@RequestMapping(method = RequestMethod.GET, value = "upload")
	public ModelAndView upload() {
		ModelAndView mv = new ModelAndView();
		mv.addObject("bucket", qiniuService.getBucketName());
		mv.setViewName("/resources/upload");
		return mv;
	}

	@RequestMapping(method = RequestMethod.GET, value = "uptoken")
	@ResponseBody
	public String getUpToken() {
		return qiniuService.simpleUploadToken();
	}

	@RequestMapping(method = RequestMethod.POST, value = "saveresource")
	public ModelAndView save(@RequestParam String category, @RequestParam String description,
			@RequestParam String fileNames) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/backstage/review");
		return mv;
	}
}
